﻿@model IEnumerable<CubicFWNet.Data.Models.Module>
@{
    ViewBag.Title = "Index";
    var modules = ViewBag.Modules as IEnumerable<CubicFWNet.Data.Models.Module>;
}

<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        系统菜单
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index","Home")">首页</a></li>
        <li class="active"><a href="@Url.Action("Index","Module")">系统菜单</a></li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-sm-12">
            <div class="box box-solid">
                <div class="box-nav clearfix">
                    <div class="col-sm-12 col-md-9">
                        <button type="button" class="btn btn-primary" onclick="create();" title="新建"><i class="fa fa-plus-square"></i>&nbsp;新建菜单</button>
                        @*<button type="button" class="btn btn-warning" oncancel="edit();" title="修改"><i class="fa fa-edit"></i></button>
                            <button type="button" class="btn btn-danger" onclick="del()" title="删除"><i class="fa fa-trash-o"></i></button>*@
                        @*<button type="button" class="btn btn-info" title="查看"><i class="fa fa-search-plus"></i></button>*@
                        <a class="btn btn-default" onclick="$.reload()" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a>
                    </div>
                    @*<div class="col-sm-12 col-md-3">
                            <input id="filter" type="text" class="form-control form-control-static" placeholder="搜索关键字">
                             <div class="input-group">
                                <span class="input-group-btn">
                                         <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                                     </span>
                              </div>
                        </div>*@
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                    <table class="footable table table-stripped table-bordered table-hover" id="footable" data-page-size="20" data-filter=#filter>
                        <thead>
                            <tr>
                                <th data-sort-ignore="true">
                                    @Html.DisplayNameFor(model => model.Name)
                                </th>
                                <th data-sort-ignore="true">
                                    @Html.DisplayNameFor(model => model.Url)
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    @Html.DisplayNameFor(model => model.CascadeId)
                                </th>
                                <th data-sort-ignore="true">
                                    @Html.DisplayNameFor(model => model.SortNo)
                                </th>
                                <th data-sort-ignore="true">
                                    @Html.DisplayNameFor(model => model.Status)
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    @Html.DisplayNameFor(model => model.IconName)
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    @Html.DisplayNameFor(model => model.IsLeaf)
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">
                                    @Html.DisplayNameFor(model => model.ParentName)
                                </th>
                                <th data-hide="phone,tablet" data-sort-ignore="true">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            @if (null != Model)
                            {
                                foreach (var item in Model)
                                {
                                    <tr>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.Name)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.Url)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.CascadeId)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.SortNo)
                                        </td>
                                        <td>
                                            @if (item.Status)
                                            {
                                                <span class="btn-xs bg-green">正常</span>
                                            }
                                            else
                                            {
                                                <span class="btn-xs bg-black">禁用</span>
                                            }
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.IconName)
                                        </td>
                                        <td>
                                            @if (item.IsLeaf)
                                            {
                                                <i class="fa fa-check" style="color: #00a65a;"></i>
                                            }
                                            else
                                            {
                                                <i class="fa fa-close warning" style=" color: #f39c12;"></i>
                                            }
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.ParentName)
                                        </td>
                                        <td>
                                            <button type="button" onclick="edit('@item.Id');" class="btn btn-xs bg-blue">编辑</button>
                                            @*<button type="button" class="btn  btn-xs btn-info btn-flat"><i class="fa fa-search"></i></button>*@
                                            <button type="button" onclick="del(this,'@item.Id');" class="btn  btn-xs bg-orange">删除</button>
                                        </td>
                                    </tr>
                                }
                            }
                        </tbody>
                        <tfoot>
                            <tr>
                                <td colspan="9">
                                    <ul class="pagination1 pagination pull-right"></ul>
                                </td>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>
<!--编辑对话框-->
<div class="modal" id="editDlg" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">添加/修改系统菜单</h4>
            </div>
            <form class="form-horizontal" id="frmedit" action="@Url.Action("Add","Module")" method="post">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 功能模块名称 </label>
                        <div class="col-sm-9">
                            <input type="hidden" class="form-control formId" id="Id" name="Id" />
                            <input type="text" class="form-control" id="Name" required name="Name" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 主页面URL </label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Url" name="Url" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 图标 </label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="IconName" name="IconName" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 排序号 </label>
                        <div class="col-sm-9">
                            <input type="number" class="form-control" id="SortNo" name="SortNo" value="0" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 子菜单 </label>
                        <label class="col-sm-9" style="padding-top:5px;">
                            <input type="checkbox" name="IsLeaf" id="IsLeaf">
                        </label>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 状态 </label>
                        <label class="col-sm-9" style="padding-top:5px;">
                            <input type="checkbox" name="Status" id="Status" checked>
                        </label>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right" for=""> 上级模块</label>
                        <div class="col-sm-9">
                            <input type="hidden" name="ParentName" id="ParentName" />
                            <select class="form-control" type="select" id="ParentId" name="ParentId">
                                <option value="">==请选择==</option>
                                @foreach (var module in modules)
                                {
                                    <option value="@module.Id.ToString()">@module.Name</option>
                                }
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>

<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">数据加载中，请稍后…</div>
</div>

@*@section Styles {
        @Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")
    }*@

@section Scripts {
    
    <script type="text/javascript">
        $(document).ready(function () {
            $('#footable').footable();
            $("#frmedit").validate({
                submitHandler: function (form) {
                    var postData = $(form).formSerialize();
                    $.submitForm({
                        url: $(form).attr("action"),
                        param: postData,
                        success: function () {
                            $.reload();
                        }
                    });
                }
            });
            //iCheck for checkbox and radio inputs
            //$('input[type="checkbox"].flat-red').iCheck({
            //    checkboxClass: 'icheckbox_flat-green',
            //    radioClass: 'iradio_flat-green'
            //});
        });

        function create() {
            $("#frmedit").formInit();
            $('#editDlg').modal();
        }

        function edit(id) {
            if (!!id) {
                $.ajax({
                    url: "/Module/GetFormJson",
                    data: { id: id },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        $("#frmedit").formSerialize(data);
                        $("#editDlg").modal();
                    }
                });
            }
        }

        function del(obj, id) {
            if (!!id) {
                $.deleteForm({
                    url: "/Module/Delete",
                    param: { id: id },
                    success: function () {
                        $(obj).parents("tr").remove();
                    }
                });
            }
        }



    </script>
}
